import 'dart:async';
import 'dart:convert';
import 'package:flutter_trip/model/travel_tab_model.dart';
import 'package:http/http.dart' as http;

const HOME_URL = 'https://www.devio.org/io/flutter_app/json/travel_page.json';

// 首页大接口
class TravelTabDao {
  static Future<TravelTabModel> fetch() async {
    // 发起请求
    final respnse = await http.get(HOME_URL);
    if (respnse.statusCode == 200) {
      Utf8Decoder utf8decoder = Utf8Decoder(); // fix 中午乱码
      var result = json.decode(utf8decoder.convert(respnse.bodyBytes)); // 解码
      return TravelTabModel.fromJson(result);
    } else {
      throw Exception('Fail to load home_page.json');
    }
  }
}
